package org.wcf.util;

/**
 * @author wuchaofei
 * @date 2016/3/22
 */
public class StringsUtil {
    public static void main(String[] args) {
        String str="23,4,26,25,22,27,16,2,15,12,5,29,28\n" +
                "24\n" +
                "21\n" +
                "20\n" +
                "19\n" +
                "18\n" +
                "17\n" +
                "14\n" +
                "13\n" +
                "11\n" +
                "10\n" +
                "9\n" +
                "8\n" +
                "7\n" +
                "3\n" +
                "6";
        System.out.println(replaceBlankAndSplit(str,","));
    }
    public static String collectKey(String s){
        String[] lines = s.split("\n");
        StringBuilder sb=new StringBuilder();

        for (int i = 0; i < lines.length; i++) {
            String line=lines[i].trim();
            if(org.apache.commons.lang3.StringUtils.isEmpty(line) || !line.contains("=")){
                continue;
            }else{
                String key = line.split("=")[0];
                if(i!=lines.length-1){
                    sb.append(key).append(",");
                }else{
                    sb.append(key);
                }
            }
        }
        return sb.toString();
    }

    /**
     *
     * @param str
     * @param dot
     * @return
     */
    public static String replaceBlankAndSplit(String str,String dot){
        if(dot==null || dot.length()==0){
            dot=",";
        }
        str = str.replaceAll("[\n| ]+?",dot);
        return str;
    }
}
